package org.gap.wizards.world.actions;

import java.awt.Point;
import java.util.List;

import org.gap.wizards.creature.DialogEngine;
import org.gap.wizards.creature.NonPlayerCharacter;
import org.gap.wizards.views.MessageOutput;
import org.gap.wizards.world.Wilderness;
import org.gap.wizards.world.WorldAction;

public class TalkWithAction implements WorldAction {

	private final MessageOutput output;
	private final Wilderness map;
	private final DialogEngine dialog;
	private final TargetSelector targetSelector;

	public TalkWithAction(MessageOutput output, Wilderness map, DialogEngine dialog, TargetSelector targetSelector) {
		this.output = output;
		this.map = map;
		this.dialog = dialog;
		this.targetSelector = targetSelector;
	}

	@Override
	public void perform() {
		output.addMessage("Whom will you speak with?");
		Point findTarget = targetSelector.findTarget(map.getCharacterLocation());
		List<Object> allFromLocation = map.getAllFromLocation(findTarget);
		for (Object each : allFromLocation) {
			if (each instanceof NonPlayerCharacter) {
				dialog.talkWith((NonPlayerCharacter)each);
				return;
			}
		}
		output.addMessage("No one to talk to there");
	}

}
